package com.pro_one.mobile.controller;

import com.pro_one.constant.MessageConstant;
import com.pro_one.entity.Result;
import com.pro_one.pojo.OrderAddress;
import com.pro_one.service.OrderAddressService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/orderaddress4mobile")
public class OrderAddressController {
    @Reference
    private OrderAddressService orderAddressService;

    /**
     * 查询所有的预约地址信息
     *
     * @return
     */
    @RequestMapping("/findAllAddress")
    public Result findAll() {
        try {
            List<OrderAddress> orderAddressList = orderAddressService.findAll();
            return new Result(true, MessageConstant.GET_ORDERADDRESS_SUCCESS, orderAddressList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ORDERADDRESS_FAIL);
        }
    }

    /**
     * 根据预约地址查询详细的地址信息对象
     * @param address
     * @return
     */
    @RequestMapping("/findDetail")
    public Result findLatitude(String address) {
        try {
            address = new String(address.getBytes("iso8859-1"), "UTF-8");
            System.out.println(address);

            OrderAddress orderAddress = orderAddressService.findOrderAddressDetailByAddress(address);
            System.out.println(orderAddress);
            return new Result(true, MessageConstant.GET_ORDERADDRESS_SUCCESS, orderAddress);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_ORDERADDRESS_FAIL);
        }
    }
}
